package com.mobile.zlb;

/**
 * 浙里办用户信息Controller
 *
 * @author mobile
 * @date 2022/4/11
 */

import com.mobile.zlb.service.IZlbClientService;
import com.ruoyi.common.annotation.RepeatSubmit;
import com.ruoyi.common.constant.ZlbConstants;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.StringUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@Api(value = "浙里办用户信息模块", tags = "浙里办用户信息模块")
@RestController
@RequestMapping("/zlb/client")
public class ZlbClientController {

    @Autowired
    private IZlbClientService zlbClientService;

    private static final Logger logger = LoggerFactory.getLogger(ZlbClientController.class);

    /**
     * 获取用户临时授权码authCode
     */
    @RepeatSubmit()
    @ApiOperation(value = "获取用户登陆票据ticket", notes = "获取用户登陆票据ticket", httpMethod = "GET")
    @ApiImplicitParam(name = "ticket", value = "登录票据", required = true, dataType = "String", paramType = "path")
    @GetMapping("/getClientTicket/{ticket}")
    public AjaxResult getClientTicket(@PathVariable String ticket) {
        if (StringUtils.isEmpty(ticket) || ZlbConstants.MSG_ERROR_PARAMETER_UNDEFINED.equals(ticket)) {
            return AjaxResult.error(ZlbConstants.MSG_ERROR_PARAMETER_WRONG);
        }
        logger.info("获取用户登陆票据ticket=" + ticket);
        return zlbClientService.getClientTicketCode(ticket);
    }

    /**
     * 根据令牌获取用户详细信息
     */
    @RepeatSubmit()
    @ApiOperation(value = "根据令牌token获取用户详细信息", notes = "根据令牌token获取用户详细信息", httpMethod = "GET")
    @ApiImplicitParam(name = "token", value = "令牌token", required = true, dataType = "String", paramType = "path")
    @GetMapping("/getClientInfo/{token}")
    public AjaxResult getClientInfoByToken(@PathVariable String token) {
        if (StringUtils.isEmpty(token) || ZlbConstants.MSG_ERROR_PARAMETER_UNDEFINED.equals(token)) {
            return AjaxResult.error(ZlbConstants.MSG_ERROR_PARAMETER_WRONG);
        }
        logger.info("用户令牌token=" + token);
        return zlbClientService.getClientInfoByToken(token);
    }

}
